﻿using Md.Api.Entity.DapperModels.MdDB;
using Md.Api.Model.Manage.SysDictData.Request;
using Md.Dapper.Repositories.Md;

namespace Md.Api.Service.Manage.SysDictData;
/// <summary>
/// 添加系统字典数据服务
/// </summary>
public class InsertSysDictDataService : ApiBase<RequestInsertSysDictDataModel>
{
    /// <summary>
    /// 系统字典数据仓储
    /// </summary>
    public SysDictDataRep sysDictDataRep { get; set; }
    /// <summary>
    /// 执行
    /// </summary>
    protected override void ExecuteMethod()
    {
        var model = new SysDictDataModel();

        model.DictSort = Parameter.DictSort;
        model.DictLabel = Parameter.DictLabel;
        model.DictValue = Parameter.DictValue;
        model.DictType = Parameter.DictType;
        model.DataType = Parameter.DataType;
        model.CssClass = Parameter.CssClass;
        model.ListClass = Parameter.ListClass;
        model.IsDefault = Parameter.IsDefault;
        model.Status = Parameter.Status;
        model.Remark = Parameter.Remark;
        model.CreateBy = userKey?.ToString();
        model.CreateTime = DateTime.Now;

        var res = sysDictDataRep.Insert(model);

        if (Convert.ToInt64(res) > 0)
        {
            Result.Data = sysDictDataRep.GetSysDictDataByDictCode(Convert.ToInt64(res));
        }
        else
        {
            Result.Data = res;
        }
    }
}

